#ifndef __SIPREGISTERSESSION_HPP__
#define __SIPREGISTERSESSION_HPP__

#include "SipGDServiceConfigure.hpp"
//#include "SipSessionBase.hpp"
#include "SipDlgSessionBase.hpp"

//#define RegisterHeart 10


namespace wtsip{

class CSipRegisterSession;


class WTGD_SIPSRV_PUBLIC CSipRegisterHandle: virtual public CSipSessionHandle
{
public:

    //virtual bool onSuccessed() = 0;

    virtual bool onDisconnected(CSipRegisterSession& regs) = 0;

    virtual bool onRejected(SipMessage& msg, CSipRegisterSession& regs) = 0;
};


class WTGD_SIPSRV_PUBLIC CSipRegisterSession: 
    public CSipDlgSessionBase
{
public:

    CSipRegisterSession(CSipGDService& sv, CSipDialogBase& dlg);

    ~CSipRegisterSession();

    virtual bool start(const std::string& body);

    //virtual bool stop();

    //virtual bool replyOK(const resip::Data& id, std::string& body);

    virtual bool replyFail(const resip::Data& id, CSipSessionBase::EFailReason r);

    virtual bool reply(const resip::Data& id, std::string& body, CSipSessionBase::EFailReason r);

    virtual bool messageDresser(SipMessage& msg);

    bool setExpires(int expr);

    int getExpires();

private:

    ///////////////////////////// CSipRegisterDlgHandle methods ////////////////////////

    virtual bool isFakeTransation(SipMessage& msg, CSipDialogBase& dlg);

    virtual bool onResponse(SipMessage& msg, CSipDialogBase& dlg);

    virtual bool onRequest(SipMessage& msg, CSipDialogBase& dlg);

    virtual bool onTimeout(ApplicationMessage& msg, CSipDialogBase& dlg);

    virtual bool onDestroy(CSipDialogBase& dlg);

private:

    bool postHeartBeat(bool staySeq = false);

    bool handleDisconnected();

    bool handleRejected(SipMessage& msg);

private:

    //CSipRegisterHandle* m_regHandle;

    int m_exprAlive;

    int m_beatSeq;

    bool m_regSuccessed;
};



}//namespace


#endif


